###理解global和nonlocal的作用

#global是为了在函数中修改全局变量的值
x = 1
def fun1():
    x = 5
    def fun2():
        global x
        x = 2
    fun2()
    print(x)

fun1()
print(x)
############################ nonlocal #####################

#nonlocal是为了嵌套函数中内部函数修改外部函数的局部变量

x = 0
def fun1():
    x = 1
    def fun2():
        x = 2
        def fun3():
            nonlocal x
            x = 3
        fun3()
        print("fun2----->"+ str(x))
    fun2()
    print("fun3------->"+ str(x))

fun1()
print(x)